package we.caro;

import java.util.Map;

import we.common.CCommonHandler;

import we.core.bean.CDataContainer;

import we.database.CDataController;

public class UserCaroInfo {
    public static UserCaroInfo getUserCaroInfo(String username){
        Map<String, Object> map;
        try {
            map =
(Map<String, Object>)CDataController.GetController().get("caro_" + username + "_info");
            return new UserCaroInfo(username, map);
        } catch (Exception e) {
            CCommonHandler.writeErrLog(e);
        }        
        return null;
    }
    
    private Map<String, Object> map;
    private String username;
    private UserCaroInfo(String username, Map<String, Object> map) {
        this.map = map;
        this.username = username;
    }
    
    public int getGold(){
      if (map == null)
          return 0;
        return (Integer) map.get("gold");
    }
    
    public int getExp(){
      if (map == null)
          return 0;
        return (Integer) map.get("exp");
    }
    
    public int getNumWin(){        
        if (map == null || !map.containsKey("numWin"))
            return 0;
        
        return (Integer) map.get("numWin");
    }
    
    public int getNumLose(){
      if (map == null || !map.containsKey("numWin"))
          return 0;
        return (Integer) map.get("numLose" );
    }
    
    public void setGold(int i){
        map.put("gold", i);
    }
            
    public void setExp(int i){
        map.put("exp", i);
    }
            
    public void setNumWin(int i){
        map.put("numWin", i);
    }
            
    public void setNumLose(int i){
        map.put("numLose", i);
    }
    
    private void writeMembase(){
        try {
            CDataController.GetController().set("caro_" + username + "_info", map);
        } catch (Exception e) {
            CCommonHandler.writeErrLog(e);
        }
    }                
}
